import {Http} from '@angular/http';
import {NgLayer, NgLayerRef} from 'ng2-layer';
import {Component,ViewContainerRef, Injectable}  from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
/**
 * 左侧菜单部分
 */
@Component({
	selector: '.box_base',
	templateUrl: 'template/router/boxSetting/base.html'
})
export class BoxBaseComp {
	box;
	colors = ["FF5959","F2CA00","00E699","5533FF","FF7919","44e645","4DB1FE","000000"];
	icons = ["&#xe600;","&#xe601;","&#xe602;","&#xe603;","&#xe604;","&#xe605;","&#xe606;","&#xe607;","&#xe608;",
			"&#xe609;","&#xe60a;","&#xe60b;","&#xe60c;","&#xe60d;","&#xe60e;","&#xe60f;","&#xe610;","&#xe611;",
			"&#xe612;","&#xe613;"];
	
	
	constructor(private http:Http, router:ActivatedRoute, private layer:NgLayer){
		router.parent.params.subscribe(params => {
			//获取盒子详细信息
			http.get({
				search:{
					m:"Admin",
					c:"ApiBox",
					a:"getBoxInfoById",
					box_id:params.id
				}
			}).then((data)=>{
				this.box = data.data;
				this.box.is_show = this.box.is_show=="0"?false:true;
			})
		});
	}
	
	/*保存盒子*/
	saveBox(){
		let box = this.box;
		this.http.post({
			search:{
				m:"Admin",
				c:"ApiBox",
				a:"updateBox"
			},
			body:{
				box_id:box.box_id,
				name:box.name,
				bg_img:box.bg_img,
				color:box.color,
				is_show:box.is_show?"1":"0"
			}
		}).then((data)=>{
			this.layer.tip({message:"修改成功", align:"top"});
		})
	}
}